<?php
/* -------------------------------------------------------------------------------------
* 	ID:						$Id: product_related_products_cat.php 135 2013-09-22 07:30:55Z phone.mueller@googlemail.com $
* 	Letzter Stand:			$Revision: 135 $
* 	zuletzt geaendert von:	$Author: siekiera $
* 	Datum:					$Date: 2013-09-22 07:30:55 +0000 (Sun, 22 Sep 2013) $
*
* 	SEO:mercari by Siekiera Media
* 	http://www.seo-mercari.de
*
* 	Copyright (c) since 2011 SEO:mercari
* --------------------------------------------------------------------------------------
* 	based on:
* 	(c) 2000-2001 The Exchange Project  (earlier name of osCommerce)
* 	(c) 2002-2003 osCommerce - www.oscommerce.com
* 	(c) 2003     nextcommerce - www.nextcommerce.org
* 	(c) 2005     xt:Commerce - www.xt-commerce.com
*
* 	Released under the GNU General Public License
* ----------------------------------------------------------------------------------- */

$module_smarty = new Smarty;
$module_smarty->assign('tpl_path', 'templates/'.CURRENT_TEMPLATE.'/');

if($_SESSION['customers_status']['customers_fsk18_display'] == '0')
	$fsk_lock = ' AND p.products_fsk18 != 1';

if(GROUP_CHECK == 'true')
	$group_check = " AND p.group_permission_".$_SESSION['customers_status']['customers_status_id']." = 1 ";

$path = explode('_', $cPath);
$cat = array_reverse($path);

$products_cat = $db->db_query_limit("SELECT
										p.products_id,
										p.products_image,
										pd.products_name
									FROM
										".TABLE_PRODUCTS." p
									LEFT JOIN ".TABLE_PRODUCTS_TO_CATEGORIES." pc ON (p.products_id = pc.products_id)
									LEFT JOIN ".TABLE_PRODUCTS_DESCRIPTION." pd ON (p.products_id = pd.products_id AND pd.language_id = '".(int) $_SESSION['languages_id']."')
									WHERE
										categories_id='".$cat[0]."'
									AND
										p.products_status = 1
									AND
										p.products_id <> '".$product->data['products_id']."'
										".$fsk_lock.$group_check."
									ORDER BY RAND()", 5, true);

if($products_cat->_numOfRows > 0) {
	$product_related_products_cat = array();
	while(!$products_cat->EOF) {
		$product_related_products_cat[] = array('pID' => $products_cat->fields['products_id'],
			                                    'pName' => $products_cat->fields['products_name'],
			                                    'pImage' => (SHOW_IMG_CAT_RELATED == 'true' && !empty($products_cat->fields['products_image']) ? DIR_WS_THUMBNAIL_IMAGES.$products_cat->fields['products_image'] : ''),
			                                    'prdlink' => href_link(FILENAME_PRODUCT_INFO, 'products_id='.$products_cat->fields['products_id']));
		$products_cat->MoveNext();
	}
}

$products_all = $db->db_query_limit("SELECT
											pc.products_id,
											p.products_image,
											pd.products_name
										FROM
											".TABLE_PRODUCTS." p
										LEFT JOIN ".TABLE_PRODUCTS_TO_CATEGORIES." pc ON (p.products_id = pc.products_id)
										LEFT JOIN ".TABLE_PRODUCTS_DESCRIPTION." pd ON (p.products_id = pd.products_id AND pd.language_id = '".(int) $_SESSION['languages_id']."')
										WHERE
											p.products_id != '".$product->data['products_id']."'
										AND
											p.products_status = 1
											".$fsk_lock.$group_check."
										ORDER BY
											RAND()", 5, true);

if($products_all->_numOfRows) {
	$product_related_products_all = array();
	while(!$products_all->EOF) {
		if(isset($products_all->fields['products_id'])) {
		    $product_related_products_all[] = array('pID' => $products_all->fields['products_id'],
		                                			'pName' => $products_all->fields['products_name'],
		                                			'pImage' => (SHOW_IMG_CAT_RELATED == 'true' && !empty($products_all->fields['products_image']) ? DIR_WS_THUMBNAIL_IMAGES.$products_all->fields['products_image'] : ''),
		                                			'prdlink' => href_link(FILENAME_PRODUCT_INFO, 'products_id='.$products_all->fields['products_id']));
		}
		$products_all->MoveNext();
	}
}
$module_smarty->assign('PRODUCT_RELATED_CAT', $product_related_products_cat);
$module_smarty->assign('PRODUCT_RELATED_CAT_ALL', $product_related_products_all);

$module_smarty->assign('language', $_SESSION['language']);

$module_smarty->caching = false;
$product_related = $module_smarty->fetch(CURRENT_TEMPLATE.'/module/products_related_products_cat.html');

$info_smarty->assign('MODUL_product_related_cat', $product_related);
?>